import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location) {
  return originalPush.call(this, location).catch(err => { })
};

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: "/login"
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: {
      isShowtabbar: 1
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "login" */ '../views/Login.vue'),
    meta: {
      isShowtabbar: 0
    }
  },
  {
    path: '/user',
    name: 'User',
    component: () => import(/* webpackChunkName: "user" */ '../views/User.vue'),
    meta: {
      isShowtabbar: 1
    },
  },
  {
    path: '/userbanben',
    name: 'Userbanben',
    component: () => import(/* webpackChunkName: "userbanben" */ '../components/Userbanben.vue'),
  },
  {
    path: '/xitong',
    name: 'Xitong',
    component: () => import(/* webpackChunkName: "xitong" */ '../views/Xitong.vue'),
    meta: {
      isShowtabbar: 0
    }
  },
  {
    path: '/star',
    name: 'Star',
    component: () => import(/* webpackChunkName: "star" */ '../views/Star.vue'),
    meta: {
      isShowtabbar: 0
    },
  },
  {
    path: '/starChildwei',
    name: 'StarChildwei',
    component: () => import(/* webpackChunkName: "starChildwei" */ '../components/StarChildwei.vue'),
  },
  {
    path: '/starChild',
    name: 'StarChild',
    component: () => import(/* webpackChunkName: "starChild" */ '../components/StarChild.vue'),
  },
  {
    path: '/productorder',
    name: 'Productorder',
    component: () => import(/* webpackChunkName: "productorder" */ '../views/Productorder.vue'),
    children: [
      {
        path: '/productpingjia',
        name: 'Productpingjia',
        component: () => import(/* webpackChunkName: "productpingjia" */ '../components/Productpingjia.vue'),
      },
      {
        path: '/productexid',
        name: 'Productexid',
        component: () => import(/* webpackChunkName: "productexid" */ '../components/Productexid.vue'),

      }
    ]
  },
  {
    path: '/message',
    name: 'Message',
    component: () => import(/* webpackChunkName: "message" */ '../views/Message.vue'),
    meta: {
      isShowtabbar: 0
    },
  },
  {
    path: '/MessageChild',
    name: 'MessageChild',
    component: () => import(/* webpackChunkName: "MessageChild" */ '../components/MessageChild.vue'),
    meta: {
      isShowtabbar: 0
    }
  },
  {
    path: '/UserMessList',
    name: 'userMessList',
    component: () => import(/* webpackChunkName: "userMessList" */ '../views/UserMessList.vue'),
    meta: {
      isShowtabbar: 0
    }
  },
  {
    path: '/UserSearch',
    name: 'userSearch',
    component: () => import(/* webpackChunkName: "userSearch" */ '../views/UserSearch.vue'),
    meta: {
      isShowtabbar: 0
    }
  },
  {
    path: '/UserListXiang',
    name: 'userListXiang',
    component: () => import(/* webpackChunkName: "userListXiang" */ '../views/UserListXiang.vue'),
    meta: {
      isShowtabbar: 0
    }
  },
  {
    path: '/UserMessChild',
    name: 'userMessChild',
    component: () => import(/* webpackChunkName: "userMessChild" */ '../components/UserMessChild.vue'),
    meta: {
      isShowtabbar: 0
    },
    children: [
      {
        path: '/BianjiUser',
        name: '/bianjiUser',
        component: () => import(/* webpackChunkName: "bianjiUser" */ '../components/BianjiUser.vue'),
      },
    ]
  },
  {
    path: '/Kehu',
    name: 'keHu',
    component: () => import(/* webpackChunkName: "keHu" */ '../views/Kehu.vue'),
    meta: {
      isShowtabbar: 0
    },
    children: [
      {
        path: '/VistXiang',
        name: '/vistXiang',
        component: () => import(/* webpackChunkName: "vistXiang" */ '../components/VistXiang.vue'),
      },
    ]
  },
  {
    path: '/NewVist',
    name: 'newVist',
    component: () => import(/* webpackChunkName: "newVist" */ '../views/NewVist.vue'),
    meta: {
      isShowtabbar: 0
    }
  },
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


router.beforeEach((to, from, next) => {
  let token = localStorage.getItem("token");
  if (to.path == "/Productorder") {
    if (token) {
      next()
    } else {
      Vue.prototype.$toast("请先登录!")
      setTimeout(() => {
        next("/login")
      }, 1000)
    }
    return
  }
  next()
})

export default router
